package _go

func matrixReshape(nums [][]int, r int, c int) [][]int {

	if r < 0 || c < 0 {
		return [][]int{}
	}

	a := len(nums)
	b := len(nums[0])

	if a*b < r*c {
		return nums
	}

	var res [][]int
	var tmp []int
	var count int = 0 //计数
	// for i:=0; i<a ;i++{
	//     for j:=0; j<b; j++{
	for _, hang := range nums {
		for _, v := range hang {

			tmp = append(tmp, v)
			//fmt.Printf("sdfs:%s\n",tmp)
			count++

			if count == c {
				res = append(res, tmp)
				tmp = []int{}
				count = 0
			}
		}
	}
	return res
}
